<?php
class Kbs_Application_Resource_Dojo extends
    Zend_Application_Resource_ResourceAbstract
{
    protected $_dojo;

    /**
     * To init the dojo
     *
     * @return Zend_Dojo $dojo
     */
    public function init()
    {
        if (null === $this->_dojo) {
            $options = $this->getOptions();

            $view = $this->getBootstrap()->bootstrap('View')
                                         ->getResource('View');

            if (isset($options['cdnversion'])) {
                $view->dojo()->setCdnVersion($options['cdnversion']);
            }

            if (isset($options['localpath'])) {
                $view->dojo()->setLocalPath($options['localpath']);
            }

            if (is_array($options['options'])) {
                foreach ($options['options'] as $name => $value) {
                    $view->dojo()->setDjConfigOption($name, $value);
                }
            }

            if ($options['enable']) {
                $view->dojo()->enable();
            } else {
                $view->dojo()->disable();
            }

            $this->_dojo = $view->dojo();
        }
        return $this->_dojo;
    }
}